package cn.edu.njupt.eclass.aixinling.controller;

import cn.edu.njupt.eclass.aixinling.domain.BaseResponse;
import cn.edu.njupt.eclass.aixinling.service.PictureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author: kent
 * @date: 2018/6/4 20:48
 */

@RestController
@RequestMapping(value = "/pictures")
@Slf4j
@CrossOrigin
public class PictureController {

    @Autowired
    PictureService pictureService;

    /**
     * 添加一个题目以及上传图片返回二维码
     * @param file
     * @return
     */
    @RequestMapping(value = "/uploadPic", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse uploadPic(@RequestParam(value = "file", required = false) MultipartFile file) {
        return pictureService.upload(file);
    }



    @RequestMapping(value="/pictest",method = RequestMethod.GET)
    @ResponseBody
    public String Pictest(){
        return "asd";
    }

    /**
     * 根据图片picId获取图片
     * @param picId
     * @param response
     */
    @RequestMapping(value = "/getPic", method = RequestMethod.GET)
    public void getPic(@RequestParam(value="picId") String picId, HttpServletResponse response) {
        pictureService.getPic(picId, response);
    }
}
